import request from '../utils/request'

const url = '/staff-leave'

// 基础接口
export const add = (data) => {
  return request({
    url: url,
    method: 'post',
    data
  })
}

export const del = (id) => {
  return request({
    url: `${url}/${id}`,
    method: 'delete'
  })
}

export const deleteBatch = (ids) => {
  return request({
    url: `${url}/batch/${ids}`,
    method: 'delete'
  })
}

export const edit = (data) => {
  return request({
    url: url,
    method: 'put',
    data
  })
}

export const list = (params) => {
  return request({
    url: url,
    method: 'get',
    params
  })
}

// 申请请假
export const apply = (data) => {
  return request({
    url: `${url}/apply`,
    method: 'post',
    data: {
      days: Number(data.days),
      typeNum: data.typeNum, // 直接传递数值类型
      code: data.code
    }
  })
}

// 审批操作
export const approve = (leaveId, data) => {
  return request({
    url: `${url}/approve/${leaveId}`,
    method: 'post',
    data // 直接传递整个参数对象
  })
}

// 数据导入导出
export const exp = (filename) => {
  return request({
    url: `${url}/export/${filename}`,
    method: 'get',
    responseType: 'blob'
  })
}

export const getImportApi = () => {
  return process.env.VUE_APP_HOST + ':' + process.env.VUE_APP_PORT + url + '/import'
}
